/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */




package learn.round1C;


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Iterator;
import java.util.Scanner;

/**
 *
 * @author robit
 */
public class RopeIntranet{

    RopeIntranet(){}

    private static Scanner s = null;
    private static PrintWriter o = null;
    /**
    * calculate the answer
    */
    private static int reckon() {
        int N=Int();
        int a[]=new int[N];
        int b[]=new int[N];
        for(int i=0;i<N;i++){
            a[i]=Int();
            b[i]=Int();
        }
        int points=0;
        for(int i=0;i<N;i++)
            for(int j=i+1;j<N;j++)
                if((a[i]>a[j]&&b[i]<b[j])||(a[i]<a[j]&&b[i]>b[j])) points++;
        return points;
    }
    private static void print(String str){
        System.out.print(str);
    }
    private static void println(String str){
        System.out.println(str);
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        // TODO code application logic here

        try {
            //String filename="test";
            String prob="A";
            //String filename=prob+"-small-practice";
            String filename=prob+"-large-practice";

            s = new Scanner(
                    new BufferedReader(new FileReader(filename+".in")));
            //s.useLocale(Locale.US);
            o = new PrintWriter(
                    new BufferedWriter(new FileWriter(filename+".out")));

            // Determine input line number
            int lineNums = s.nextInt();

            for (int i = 1; i <= lineNums; i++) {
                o.println("Case #" + i + ": " + reckon());
            }
        } finally {
            s.close();
            o.close();
        }
    }


    private static int Int(){
        return s.nextInt();
    }
    private static long Long(){
        return s.nextLong();
    }
    private static String String(){
        return s.next();
    }

}
